package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbAddressMapper;
import com.dongdongshop.pojo.TbAddress;
import com.dongdongshop.pojo.TbAddressExample;
import com.dongdongshop.service.TbAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class TbAddressServiceImpl implements TbAddressService {

    @Autowired
    private TbAddressMapper tbAddressMapper;
    @Override
    public List<TbAddress> selectById(String username) {
        TbAddressExample tbAddressExample = new TbAddressExample();
        TbAddressExample.Criteria criteria = tbAddressExample.createCriteria();
        criteria.andUserIdEqualTo(username);
        List<TbAddress> tbAddressList = tbAddressMapper.selectByExample(tbAddressExample);
        return tbAddressList;
    }

    @Override
    public void addAddress(TbAddress address) {
        tbAddressMapper.insertSelective(address);
    }

    @Override
    public void deleteAddress(Long id) {
        tbAddressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateAddress(Long id, String username) {
        tbAddressMapper.updateAddress(username);
        tbAddressMapper.updateByID(id);

    }
}
